import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;


public class CalendarWindow extends JFrame{

	private Application controller;
	
	private CalendarWidget calendar;
	public EventsView eventsView;
	private JScrollPane scrollPane;
	public DayInfo dayInfo;
	private JPanel calendarPanel;
	
	private JMenuBar menuBar;
	private JMenu fileMenu;
	private JMenuItem newEvent;
	private JMenu exportSubmenu;
	private JMenuItem toEvolution;
	private JMenuItem toXML;
	private JMenuItem toSQL;
	private JMenu importSubmenu;
	private JMenuItem fromEvolution;
	private JMenuItem fromXML;
	private JMenuItem fromSQL;
	private JMenuItem settings;
	private JMenuItem exit;
	
	private JButton add;
	private JButton remove;
	private JButton edit;
	private JTextField filter;
	
	class toolBarListener implements ActionListener 
	{
		JButton add;
		JButton edit;
		JButton remove;
		Application controller;
		
		toolBarListener (Application controller, JButton add, JButton edit, JButton remove)
		{
			this.add=add;
			this.edit=edit;
			this.remove=remove;
			this.controller=controller;
		}
	
		public void actionPerformed(ActionEvent evt) 
		{
			if (evt.getSource() == add)
			{return;}
			if (evt.getSource()==edit)	
			{return;}
			if (evt.getSource()==remove)
			{return;}
			
			
		}

	}
	

	public static void main(String[] args) {
		new Application();

	}
	
	void createToolBar (JToolBar t)
	{
		t.add(add = new JButton("Dodaj"));
		t.add(edit =new JButton("Edytuj"));
		t.add(remove = new JButton ("usuń"));
		filter = new JTextField();
		filter.setColumns(10);
        t.add(filter);
		
	}
	
	public CalendarWindow (Application controler)
	{
		this.setPreferredSize(new Dimension(250,200));
		this.controller=controler;
		JToolBar toolBar = new JToolBar();
		
		createMenu ();
		setJMenuBar(menuBar);
		createToolBar(toolBar);
		setLayout(new BorderLayout());
		calendarPanel = new JPanel (new BorderLayout());
		calendar = new CalendarWidget(controller);
		dayInfo = new DayInfo();
		//do wyjebania stad
		String [][] data = new String[6][7];
		data[0][0]="string";
		String col[] = {"Pn"};
		DefaultTableModel model = new DefaultTableModel(data, col);
		//koniec wyjebania
		eventsView = new EventsView (24,1);
		eventsView.setModel(model);
		scrollPane = new JScrollPane(eventsView);
		add(scrollPane,BorderLayout.CENTER);
		calendarPanel.add(calendar,BorderLayout.NORTH);
		calendarPanel.add(dayInfo,BorderLayout.CENTER);
		add(calendarPanel,BorderLayout.EAST);
		add(toolBar, BorderLayout.PAGE_START);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(new Dimension(900, 400));
        setVisible(true);
        //EventDialog w = new EventDialog(this,"test");
       // w.setVisible(true);
		//w.exec();

	}
	private void createMenu ()
	{
		menuBar = new JMenuBar();
		menuBar.add(fileMenu= new JMenu("Plik"));
		fileMenu.add(newEvent = new JMenuItem("Nowe wydarzenie"));
		fileMenu.add(exportSubmenu = new JMenu("Eksport"));
		exportSubmenu.add(toEvolution = new JMenuItem("do Evolution"));
		exportSubmenu.add(toXML = new JMenuItem("do XML"));
		exportSubmenu.add(toSQL = new JMenuItem("do SQL"));
		fileMenu.add(importSubmenu = new JMenu("Import"));
		importSubmenu.add(fromEvolution = new JMenuItem ("z Evolution"));
		importSubmenu.add(fromXML = new JMenuItem ("z XML"));
		importSubmenu.add(fromSQL = new JMenuItem ("z SQL"));
		fileMenu.add(settings = new JMenuItem("Ustawienia"));
		fileMenu.add(exit = new JMenuItem("Wyjście"));
	}
	
	public void setModel (DefaultTableModel tmodel)
	{
		eventsView.setModel(tmodel);
	}
	//listenery
	

}
